import { legacy_createStore as createStore } from "redux";

function reducer(state, actions) {
  console.log(state, 1111, actions);
  if (actions.type == "ADD") {
    const copystate = { ...state };
    copystate.password = actions.password;
    copystate.email = actions.email;
    return copystate;
  } else if (actions.type == "ADDS") {
    console.log(state, 2222, actions);
    const copystate = { ...state };
    copystate.name = actions.name;
    copystate.title = actions.title;
    copystate.time = actions.time;
    copystate.address = actions.address;
    copystate.phone = actions.phone;
    copystate.img = actions.img;
    return copystate;
  } else if (actions.type == "Lg") {
    console.log(state, 333, actions);
    const copystate = { ...state };
    copystate.lemail = actions.lemail;
    localStorage.setItem("lemail", actions.lemail);
    localStorage.setItem("lphone", "");
    return copystate;
  } else if (actions.type == "Lp") {
    console.log(state, 444, actions);
    const copystate = { ...state };
    copystate.lphone = actions.lphone;
    localStorage.setItem("lphone", actions.lphone);
    localStorage.setItem("lemail", "");
    return copystate;
  } else {
    return state;
  }
}

const store = createStore(reducer, {
  password: "",
  email: "",
  name: "",
  title: "",
  time: "",
  address: "",
  phone: "",
  sex: "男",
  img: "",
  lemail: "",
  lphone: "",
});

export default store;
